<!DOCTYPE html>

<html>
<head>
  <title>createMapView.coffee</title>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <link rel="stylesheet" media="all" href="public/stylesheets/normalize.css" />
  <link rel="stylesheet" media="all" href="docco.css" />
</head>
<body>
  <div class="container">
    <div class="page">

      <div class="header">
        
          <h1>createMapView.coffee</h1>
        

        
          <div class="toc">
            <h3>Table of Contents</h3>
            <ol>
              
                
                <li>
                  <a class="source" href="admin.html">
                    admin.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="api.auditData.html">
                    api.auditData.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="api.auditEvent.html">
                    api.auditEvent.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="api.html">
                    api.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="api.entity.html">
                    api.entity.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="api.map.html">
                    api.map.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="api.server.html">
                    api.server.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="api.variable.html">
                    api.variable.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="api.view.html">
                    api.view.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="app.instance.html">
                    app.instance.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="appjs.html">
                    appjs.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="data.html">
                    data.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="dataUtil.html">
                    dataUtil.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="manager.html">
                    manager.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="messages.html">
                    messages.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="auditData.html">
                    auditData.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="auditEvent.html">
                    auditEvent.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="base.html">
                    base.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="entityDefinition.html">
                    entityDefinition.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="entityObject.html">
                    entityObject.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="eventAction.html">
                    eventAction.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="eventRule.html">
                    eventRule.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="link.html">
                    link.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="map.html">
                    map.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="shape.html">
                    shape.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="user.html">
                    user.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="userSettings.html">
                    userSettings.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="variable.html">
                    variable.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="adminRoutes.html">
                    adminRoutes.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="appRoutes.html">
                    appRoutes.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="settings.html">
                    settings.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="sockets.html">
                    sockets.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="tutorial.html">
                    tutorial.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="vectors.html">
                    vectors.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="statusTabView.html">
                    statusTabView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="toolsTabView.html">
                    toolsTabView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="usersTabView.html">
                    usersTabView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="adminView.html">
                    adminView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="alertView.html">
                    alertView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="auditDataManagerView.html">
                    auditDataManagerView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="auditEventManagerView.html">
                    auditEventManagerView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="baseView.html">
                    baseView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="createMapView.html">
                    createMapView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="entityManagerView.html">
                    entityManagerView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="footerView.html">
                    footerView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="helpView.html">
                    helpView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="entitiesTabView.html">
                    entitiesTabView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="inspectorTabView.html">
                    inspectorTabView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="mapTabView.html">
                    mapTabView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="shapeTabView.html">
                    shapeTabView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="controlsView.html">
                    controlsView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="labelEditView.html">
                    labelEditView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="linkCreatorView.html">
                    linkCreatorView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="linkLabelsView.html">
                    linkLabelsView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="linkView.html">
                    linkView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="shapeLabelsView.html">
                    shapeLabelsView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="shapeView.html">
                    shapeView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="shapesMoverView.html">
                    shapesMoverView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="mapView.html">
                    mapView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="menuView.html">
                    menuView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="overlayView.html">
                    overlayView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="scriptEditorView.html">
                    scriptEditorView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="settingsView.html">
                    settingsView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="startView.html">
                    startView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="variableManagerView.html">
                    variableManagerView.coffee
                  </a>
                </li>
              
            </ol>
          </div>
        
      </div>

      
        
        <h2 id="create-map-view">CREATE MAP VIEW</h2>

        
      
        
        <p>Represents the &quot;Create new map&quot; overlay what shows up when user
clicks a &quot;Create new...&quot; option on the top menu.</p>

        
          <div class='highlight'><pre><span class="class"><span class="keyword">class</span> <span class="title">SystemApp</span>.<span class="title">CreateMapView</span> <span class="keyword">extends</span> <span class="title">SystemApp</span>.<span class="title">OverlayView</span></span>

    <span class="attribute">$txtName</span>: <span class="literal">null</span>      <span class="comment"># the text field to enter the new map name</span>
    <span class="attribute">$menuItem</span>: <span class="literal">null</span>     <span class="comment"># the top menu DOM element</span></pre></div>
        
      
        
        <h2 id="init-and-dispose">INIT AND DISPOSE</h2>

        
      
        
        <p>Init the &quot;Create Map&quot; overlay view.</p>

        
          <div class='highlight'><pre>    <span class="attribute">initialize</span>:<span class="function"> =&gt;</span>
        <span class="property">@overlayInit</span> <span class="string">"#map-create-overlay"</span>
        <span class="property">@setDom</span>()
        <span class="property">@setEvents</span>()</pre></div>
        
      
        
        <p>Clear contents and dispose the view.</p>

        
          <div class='highlight'><pre>    <span class="attribute">dispose</span>:<span class="function"> =&gt;</span>
        <span class="property">@baseDispose</span>()</pre></div>
        
      
        
        <p>Set the DOM elements cache.</p>

        
          <div class='highlight'><pre>    <span class="attribute">setDom</span>:<span class="function"> =&gt;</span>
        <span class="property">@$txtName</span> = $ <span class="string">"#map-create-overlay-name"</span>
        <span class="property">@$menuItem</span> = $ <span class="string">"#menu-createmap"</span></pre></div>
        
      
        
        <p>Bind events to DOM and other controls.</p>

        
          <div class='highlight'><pre>    <span class="attribute">setEvents</span>:<span class="function"> =&gt;</span>
        <span class="property">@$txtName</span>.keyup <span class="property">@keyUp</span></pre></div>
        
      
        
        <h2 id="show-and-hide">SHOW AND HIDE</h2>

        
      
        
        <p>Hide the view using a fade out effect.</p>

        
          <div class='highlight'><pre>    <span class="attribute">onHide</span>:<span class="function"> =&gt;</span>
        $(<span class="built_in">document</span>).unbind <span class="string">"keyup"</span>, <span class="property">@keyUp</span>
        SystemApp.footerView.setText <span class="literal">null</span>
        <span class="property">@$el</span>.fadeOut SystemApp.Settings.general.fadeDelay</pre></div>
        
      
        
        <p>Show the view using a fade in effect and pass the entity type.
If user has no &quot;mapcreate&quot; role, hide the view immediately.</p>

        
          <div class='highlight'><pre>    <span class="attribute">onShow</span>:<span class="function"> =&gt;</span>
        <span class="keyword">if</span> <span class="keyword">not</span> SystemApp.Data.loggedUser.hasRole <span class="string">"mapcreate"</span>
            errorMsg = SystemApp.Messages.errNoPermissionTo.replace <span class="string">"#"</span>, SystemApp.Messages.createMaps
            SystemApp.alertEvents.trigger <span class="string">"tooltip"</span>, {<span class="attribute">isError</span>: <span class="literal">true</span>, <span class="attribute">title</span>: SystemApp.Messages.accessDenied, <span class="attribute">message</span>: errorMsg}</pre></div>
        
      
        
        <p>Cancel the view and go to previous screen.</p>

        
          <div class='highlight'><pre>            <span class="function"><span class="title">cancelShow</span> = =&gt;</span>
                <span class="property">@hide</span>()
                window.history.back()
            setTimeout cancelShow, <span class="number">10</span>

            <span class="keyword">return</span>

        $(<span class="built_in">document</span>).keyup <span class="property">@keyUp</span>
        SystemApp.footerView.setText SystemApp.Messages.createMapText
        <span class="property">@$el</span>.fadeIn SystemApp.Settings.general.fadeDelay, <span class="property">@focus</span></pre></div>
        
      
        
        <p>Clear and set focus on the textbox.</p>

        
          <div class='highlight'><pre>        <span class="property">@$txtName</span>.val <span class="string">""</span>
        <span class="property">@$txtName</span>.focus()

        SystemApp.menuEvents.trigger <span class="string">"active:menu"</span>, <span class="property">@$menuItem</span></pre></div>
        
      
        
        <p>When user presses a key on the <code>txtName</code> field.</p>

        
          <div class='highlight'><pre>    <span class="attribute">keyUp</span>: <span class="function"><span class="params">(e)</span> =&gt;</span>
        <span class="keyword">if</span> e.which <span class="keyword">is</span> <span class="number">27</span>
            <span class="property">@hide</span> e

        <span class="keyword">if</span> e.which <span class="keyword">is</span> <span class="number">13</span>
            newMapName = $.trim <span class="property">@$txtName</span>.val()
            existing = SystemApp.Data.maps.where {<span class="attribute">name</span>: newMapName}

            <span class="keyword">if</span> existing.length &gt; <span class="number">0</span>
                errTitle = SystemApp.Messages.errCreatingMap
                errMessage = SystemApp.Messages.errMapNameExists.replace <span class="string">"#"</span>, newMapName
                SystemApp.alertEvents.trigger <span class="string">"footer"</span>, {<span class="attribute">title</span>: errTitle, <span class="attribute">message</span>: errMessage, <span class="attribute">isError</span>: <span class="literal">true</span>}
                <span class="property">@warnField</span> <span class="property">@$txtName</span>
                <span class="keyword">return</span>

            map = SystemApp.Data.maps.create {<span class="attribute">dateCreated</span>: <span class="keyword">new</span> Date(), <span class="attribute">name</span>: newMapName}

            <span class="property">@hide</span>()</pre></div>
        
      
        
        <p>Change the URL using the new map key.</p>

        
          <div class='highlight'><pre>            SystemApp.routes.navigate <span class="string">"map/"</span> + map.urlKey(), {<span class="attribute">trigger</span>: <span class="literal">true</span>}</pre></div>
        
      
      <div class="fleur">h</div>
    </div>
  </div>
</body>
</html>
